<template>
  <div class="createPost-main-container">
    <el-form label-width="120px">
      <el-form-item label="原密码">
        <el-input v-model="oldPassword" type="password" show-password />
      </el-form-item>

      <el-form-item label="新密码">
        <el-input v-model="newPassword" type="password" show-password />
      </el-form-item>
    </el-form>
    <sticky :class-name="'cms-sub-navbar '+ajaxStatus">
      <el-button :loading="ajaxStatus" style="margin-left: 10px;" type="success" @click="commit()">
        提交
      </el-button>
      <el-button :loading="ajaxStatus" @click="reset()">
        取消
      </el-button>
    </sticky>
  </div>
</template>

<script>
import Sticky from '@/components/Sticky'
import request from '@/utils/request'
export default {
  components: {
    Sticky
  },
  data() {
    return {
      oldPassword: '',
      newPassword: ''
    }
  },
  methods: {
    commit() {
      request({
        url: '/admin/changePassword',
        method: 'post',
        data: {
          oldPassword: this.oldPassword,
          newPassword: this.newPassword
        }
      }).then(resp => {
        if (resp.errCode === 0) {
          this.$notify({
            title: '成功',
            message: '操作成功',
            type: 'success',
            duration: 2000,
          })
          // 退出登录
          this.$store.dispatch('user/logout').then(() => {
            this.$router.push(`/login?redirect=${this.$route.fullPath}`)
          })
        } else if (resp.errCode === 401) {
          // 退出登录
          this.$store.dispatch('user/logout').then(() => {
            this.$router.push(`/login?redirect=${this.$route.fullPath}`)
          })
        }
      })
    },
    reset() {}
  }
}
</script>

<style scoped>

</style>
